import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

//问题描述：重复点击导航时，控制台出现报错 ，虽然不影响功能使用，但也不能坐视不管。
const VueRouterReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(to) {
  return VueRouterReplace.call(this, to).catch(err => err);
};
const VueRouterPush = VueRouter.prototype.push;
VueRouter.prototype.push = function replace(to) {
  return VueRouterPush.call(this, to).catch(err => err);
};

const routes = [
  {
    path: "/",
    redirect: "/home"
  },
  {
    path: "/home",
    component: () => import("@/views/home/Home")
  },
  {
    path: "/category",
    component: () => import("@/views/category/Category")
  },
  {
    path: "/cart",
    component: () => import("@/views/cart/Cart")
  },
  {
    path: "/profile",
    component: () => import("@/views/profile/Profile")
  },
  {
    path: "/detail/:iid",
    component: () => import("@/views/detail/Detail")
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
